#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 200
#define MAXLEN 2010

typedef struct
{
    char* ch;
    int length;
}string;
typedef int status;

status Assign(string* str, char* chars);
status Clear(string* str);
int Length(string* str);
status Concat(string* res, string* s1, string* s2);
status Substr(string* res, string* str, int pos, int len);

string str[N];

int main()
{
    freopen("6-1.in","r",stdin);
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        char temp[MAXLEN];
        scanf("%s", temp);
        Assign(str + i, temp);
    }
    
    for (int i = 0; i < m; i++)
    {
        int op;
        scanf("%d", &op);
        string* product = NULL;
        switch (op)
        {
            case 1:
            {
                int a, b;
                scanf("%d %d", &a, &b);
                product = (string*)malloc(sizeof(string));
                product->ch = NULL;
                Concat(product, str + a, str + b);
                break;
            }
            case 2:
            {
                int a, b, c;
                scanf("%d %d %d", &a, &b, &c);
                product = (string*)malloc(sizeof(string));
                product->ch = NULL;
                Substr(product, str + a, b, c);
                break;
            }
        }
        if (product)
        {
            printf("%s\n", product->ch);
            Clear(product);
        }
    }
    return 0;
}

/* 请在这里填写答案 */
status Assign(string* str, char* chars)
{
    str->length=strlen(chars);
    str->ch=(char*)malloc(str->length+1);
    memcpy(str->ch,chars,str->length);
    str->ch[str->length]=0;
}
status Clear(string* str)
{
    str->length=0;
    free(str->ch);
    str->ch=NULL;
}
int Length(string* str)
{
    return str->length;
}
status Concat(string* res, string* s1, string* s2)
{
    res->length=s1->length+s2->length;
    res->ch=(char*)malloc(res->length+1);
    memcpy(res->ch,s1->ch,s1->length);
    memcpy(res->ch+s1->length,s2->ch,s2->length);
    res->ch[res->length]=0;
}
status Substr(string* res, string* str, int pos, int len)
{
    res->length=len;
    res->ch=(char*)malloc(res->length+1);
    memcpy(res->ch,str->ch+pos,len);
    res->ch[res->length]=0;
}